using NUnit.Framework;

namespace Avanzis.QueryObjects.Tests
{
    [TestFixture]
    public class ReadOnlyPropertiesTest : BaseTest
    {

        [SetUp]
        public void ManualInsert()
        {
            base.Setup();

            ExecuteNonQuery("DELETE FROM Competitions WHERE Code = 'XY' OR Code = 'YX'");
            ExecuteNonQuery("INSERT INTO Competitions (Code, CompetitionName, CompetitionType, CountryCode) VALUES ('XY', 'XY Competition', 'N', 'ES')");
        }        

        [Test]
        public void TestDoNotInsert()
        {
            Competition competition = new Competition();
            competition.Code = "YX";
            competition.Name = "yx COMPETITION";
            competition.CountryCode = "UK";
            competition.Type = "S";
            competition.Save();

            // CompetitionType se debe insertar pero CountryCode no

            competition = Competition.FindByPrimaryKey("YX");

            Assert.AreEqual("YX", competition.Code);
            Assert.AreEqual("yx COMPETITION", competition.Name);
            Assert.AreEqual("S", competition.Type);
            Assert.AreNotEqual("UK", competition.CountryCode);           
            
        }

        [Test]
        public void TestDoNotUpdate()
        {
            Competition competition = Competition.FindByPrimaryKey("XY");

            Assert.AreEqual("XY", competition.Code);
            Assert.AreEqual("XY Competition", competition.Name);
            Assert.AreEqual("N", competition.Type);
            Assert.AreEqual("ES", competition.CountryCode);

            // CompetitionType no se debe actualizar pero CountryCode si
            competition.Name = "New competition";
            competition.Type = "S";
            competition.CountryCode = "UK";
            competition.Save();

            competition = Competition.FindByPrimaryKey("XY");

            Assert.AreEqual("XY", competition.Code);
            Assert.AreEqual("New competition", competition.Name);
            Assert.AreEqual("N", competition.Type);
            Assert.AreEqual("UK", competition.CountryCode);

        }



    }
}
